// component/license-plate/license-plate.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    firstRow: [],
    secondRow: [],
    thirdRow: [],
    fourthRow: [],
    currentFocus: 0,
    tabIndex: '0' //0-蓝牌，1-新能源
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 输入省份
    inpuProvince: function (e) {
      var first = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'];
      var second = ['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'O', 'P'];
      var third = ['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L'];
      var fourth = ['Z', 'X', 'C', 'V', 'B', 'N', 'M']
      console.log(e)
      this.triggerEvent('inputProvince', e.currentTarget.dataset.name)
      this.setData({
        currentFocus: 1,
        firstRow: first,
        secondRow: second,
        thirdRow: third,
        fourthRow: fourth
      })
    },

    loadkeyboard: function (e, tab) {
      console.log(e)
      if (e == 0) {
        console.log('aaa')
        this.setData({
          currentFocus: 0,
          firstRow: ['苏', '京', '津', '沪', '翼', '渝', '黑', '吉', '辽'],
          secondRow: ['晋', '青', '豫', '皖', '浙', '闽', '赣', '湘', '鄂'],
          thirdRow: ['粤', '琼', '甘', '陕', '贵', '云', '川', '蒙'],
          fourthRow: ['新', '藏', '宁', '桂', '港', '澳']
        })
      } else {
        console.log('bbb')
        this.setData({
          currentFocus: e,
          firstRow: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
          secondRow: ['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'O', 'P'],
          thirdRow: ['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L'],
          fourthRow: ['Z', 'X', 'C', 'V', 'B', 'N', 'M']
        })
      }
      this.data.tabIndex = tab
    },

    // 输入市
    inputCity: function (e) {
      var first = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'];
      var second = ['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'O', 'P'];
      var third = ['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L'];
      var fourth = ['Z', 'X', 'C', 'V', 'B', 'N', 'M']
      console.log(e)
      this.triggerEvent('inputCity', e.currentTarget.dataset.name)
      this.setData({
        currentFocus: 2,
        firstRow: first,
        secondRow: second,
        thirdRow: third,
        fourthRow: fourth
      })
    },

    // 输入车牌
    inputLicense: function (e) {
      if (e.currentTarget.dataset.name != 'O') {
        //蓝牌
        if (this.data.tabIndex == '0' && this.data.currentFocus != 7) {
          this.triggerEvent('inputLicense', e.currentTarget.dataset.name)
          this.setData({
            currentFocus: this.data.currentFocus + 1
          })
        } else if (this.data.tabIndex == '1' && this.data.currentFocus != 8) { //新能源
          this.triggerEvent('inputLicense', e.currentTarget.dataset.name)
          this.setData({
            currentFocus: this.data.currentFocus + 1
          })
        } else {
          return;
        }
      }

    },

    backSpace: function () {
      if (this.data.currentFocus > 2) {
        this.setData({
          currentFocus: this.data.currentFocus - 1
        })
        this.triggerEvent('backspace', this.data.currentFocus)
      } else if (this.data.currentFocus == 2) {
        this.setData({
          currentFocus: this.data.currentFocus - 1
        })
        this.triggerEvent('backspace', this.data.currentFocus)
      } else if (this.data.currentFocus == 1) {
        this.setData({
          currentFocus: this.data.currentFocus - 1,
          firstRow: ['苏', '京', '津', '沪', '翼', '渝', '黑', '吉', '辽'],
          secondRow: ['晋', '青', '豫', '皖', '浙', '闽', '赣', '湘', '鄂'],
          thirdRow: ['粤', '琼', '甘', '陕', '贵', '云', '川', '蒙'],
          fourthRow: ['新', '藏', '宁', '桂', '港', '澳']
        })
        this.triggerEvent('backspace', this.data.currentFocus)
      } else {
        return;
      }
    },

    closeKeyBoard: function () {
      this.triggerEvent('closeKeyBoard')
    }

  }
})